package com.data.mv.mappers.oracle;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface OracleMapper {

    @Select("select tc.TABLE_NAME,\n" +
            "       tc. COLUMN_NAME,\n" +
            "       tc.DATA_TYPE,\n" +
            "       to_char(tc.DATA_LENGTH) DATA_LENGTH,\n" +
            "       tc.NULLABLE,\n" +
            "       tc.DATA_DEFAULT,\n" +
            "       cc.comments\n" +
            "  from user_tab_columns tc\n" +
            "  join user_col_comments cc\n" +
            "    on tc.TABLE_NAME = cc.table_name\n" +
            "   and tc.COLUMN_NAME = cc.column_name\n" +
            " order by tc.TABLE_NAME,tc.NULLABLE,tc.DATA_TYPE\n")
    List<Map<String, String>> getTableInfo();

    @Select("select tc.TABLE_NAME,\n" +
            "       tc. COLUMN_NAME,\n" +
            "       tc.DATA_TYPE,\n" +
            "       to_char(tc.DATA_LENGTH) DATA_LENGTH,\n" +
            "       tc.NULLABLE,\n" +
            "       tc.DATA_DEFAULT,\n" +
            "       cc.comments\n" +
            "  from user_tab_columns tc\n" +
            "  join user_col_comments cc\n" +
            "    on tc.TABLE_NAME = cc.table_name\n" +
            "   and tc.COLUMN_NAME = cc.column_name\n" +
            "   and tc.TABLE_NAME like 'SYNC%'\n" +
            " order by tc.TABLE_NAME, tc.NULLABLE, tc.DATA_TYPE\n")
    List<Map<String, String>> getSyncTableInfo();

    @Select("select count(1) from ${tableName}")
    int countTable(@Param("tableName") String tableName);

    @Select("${sql}")
    List<Map<String, Object>> select(@Param("sql") String sql);
}
